import settings
import bsddb
import struct
import sys

class Database:
    def __init__(self):
        self.webgraph = bsddb.btopen(settings.db_webgraph,'c')
        self.hashurl = bsddb.btopen(settings.db_hashurl,'c')

    def addurl(self,url):
        if not self.hashurl.has_key(url) :
            id = len(self.hashurl)
            self.hashurl[str(url)] = str(id)
            self.hashurl.sync()
            return True
        else:
            return False

    def close(self):
        self.hashurl.close()
        self.webgraph.close()
    def __del__(self):
        self.hashurl.close()
        self.webgraph.close()


##def sync(:
    ##url.sync()
    ##id.sync()


##def __del__(:
    ##url.close() 
    ##id.close()
    ##iddata.close()

#if __name__ == "__main__" :
    #db = Database()
    #del db

#def close():
    #global db_url
    #db_url.close()
